//
//  JKRFeedDetailContentView.m
//  JKRFeedDemo
//
//  Created by Lucky on 2017/12/10.
//  Copyright © 2017年 Lucky. All rights reserved.
//

#import "JKRFeedDetailContentView.h"

@interface JKRFeedDetailContentView ()

@property (nonatomic, strong) YYLabel *contentLabel;
@property (nonatomic, strong) NSMutableArray<UIImageView *> *images;

@end


@implementation JKRFeedDetailContentView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    self.backgroundColor = [UIColor whiteColor];
    _contentLabel = [self _creatYYLabel];
    _images = [NSMutableArray array];
    [self addSubview:_contentLabel];
    for (NSUInteger i = 0; i < 9; i++) {
        UIImageView *imageView = [UIImageView new];
        imageView.contentMode = UIViewContentModeScaleAspectFill;
        imageView.layer.cornerRadius = 4.f;
        imageView.layer.masksToBounds = YES;
        [self addSubview:imageView];
        [self.images addObject:imageView];
    }
    return self;
}

- (void)setLayout:(JKRFeedContentLayout *)layout {
    _layout = layout;
    self.frame = layout.contentFrame;
    self.contentLabel.frame = layout.contentLabelFrame;
    self.contentLabel.textLayout = layout.contentLabelLayout;
    for (NSUInteger i = 0; i < self.images.count; i++) {
        if (i < layout.imageFrames.count) {
            self.images[i].hidden = NO;
            self.images[i].frame = layout.imageFrames[i].CGRectValue;
            [self.images[i] setImageWithURL:layout.imageURLs[i] placeholder:nil];
        } else {
            self.images[i].hidden = YES;
        }
    }
}

- (YYLabel *)_creatYYLabel {
    YYLabel *label = [YYLabel new];
    label.ignoreCommonProperties = YES;
    label.fadeOnAsynchronouslyDisplay = YES;
    return label;
}

@end
